package com.tvunetworks.center.user.service.impl;

import com.tvunetworks.center.common.constant.LocalConstant;
import com.tvunetworks.center.gs.model.TokenRequest;
import com.tvunetworks.center.user.mapper.TokenRequestMapper;
import com.tvunetworks.center.user.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program:
 * @description:
 * @author HenryChen
 * @create: 5/29/2019 1:06 PM
 **/
@Service
public class TokenServiceImpl implements TokenService {

    @Autowired
    private TokenRequestMapper tokenRequestMapper;

    @Override
    public Integer getGridTokenPairStatus(TokenRequest tokenRequest) {

        tokenRequest.setDeleteFlag(0);
        tokenRequest.setExpireFlag(0);

        int result = 0;

        tokenRequest.setStatus(LocalConstant.GridTokenPairStatus.ACCEPT);
        result = tokenRequestMapper.selectCount(tokenRequest);
        if (result > 0) {
            return LocalConstant.GridTokenPairStatus.ACCEPT;
        }

        tokenRequest.setStatus(LocalConstant.GridTokenPairStatus.WAIT);
        result = tokenRequestMapper.selectCount(tokenRequest);
        if (result > 0) {
            return LocalConstant.GridTokenPairStatus.WAIT;
        }


        tokenRequest.setStatus(LocalConstant.GridTokenPairStatus.REJECT);
        result = tokenRequestMapper.selectCount(tokenRequest);
        if (result > 0) {
            return LocalConstant.GridTokenPairStatus.REJECT;
        }

        return null;
    }
}
